package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 插入分类数据
     * @param category
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user) " +
            "values(#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser});")
    void insert(Category category);

    /**
     * 条件查询
     * @param categoryPageQueryDTO
     * @return
     */
    List<Category> list(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 根据 id 查询分类
     * @param id
     * @return
     */
    @Select("select * from category where id = #{id}")
    Category selectById(Long id);

    /**
     * 分类信息编辑
     * @param category
     */
    @AutoFill(OperationType.UPDATE)
    void update(Category category);

    /**
     * 根据 id 删除分类
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据类型查询分类
     *
     * @param type
     * @return
     */
    List<Category> getByType(@Param("type") Integer type);
}
